{extend name="common/common" /}
	{block name="main"}
		<!-- 引入左侧栏 -->
		{include file="common/nav-header" /}
		 <div class="layui-body">
    	<!-- 内容主体区域 -->
	  	<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
			<div class="layui-tab-content site-demo site-demo-body">
			  <div class="layui-tab-item layui-show">
				<div class="layui-main">
				  <div id="LAY_preview">

             
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>默认表格</legend>
</fieldset>
<table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
 
          </div>
          
        </div>
      </div>
	   </div>
      
		<script>
		layui.use('table', function(){
		  var table = layui.table;
		  table.render({
			elem: '#test'
			,url:'/admin/Service/select'
			,cellMinWidth: 80
			,cols: [[
			   {type:'checkbox', fixed: 'left'}
			  ,{field:'id', title: 'ID', sort: true}
			  ,{field:'sid', title: '学号', sort: true}
			  ,{field:'classid', title: '班级代码'}
			  ,{field:'grade', title: '分数', sort: true}
			  ,{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}
			]]
			,where:{flag:'student'}
			,page: true
		  });
			  //监听表格复选框选择
			  table.on('checkbox(test)', function(obj){
				console.log(obj)
			  });
		    //监听工具条
			  table.on('tool(test)', function(obj){
				var data = obj.data;
				if(obj.event === 'del'){
				  layer.confirm('真的删除行么'+data.sid, function(index){
					obj.del();
					layer.close(index);
					$.ajax({
						type:"post",
						url:"{:url('admin/Service/del')}?id="+data.id+"&flag=student",
						async:true
					});
				  });
				} else if(obj.event === 'edit'){
				 layer.open({
					  type: 2, 
					  title:'编辑',
					  area: ['630px', '530px'],
					  content: "__ROOT__/admin/index/edit?id="+data.id+"&flag=student",
					  end: function () {
						table.reload('test', {
						  url: '/admin/Service/select'
						});
					  }
					}); 
				}
			  });
			  
			
		});
		</script>
	{/block}